package cn.maszy.action.systemsetting;

import java.util.List;
import net.sourceforge.stripes.action.SessionScope;
import org.springframework.beans.factory.annotation.Autowired;
import cn.maszy.common.BaseAction;
import cn.maszy.common.Pager;
import cn.maszy.common.Transcoding;
import cn.maszy.model.systemsetting.B_T_Ufp_Category;
import cn.maszy.service.systemsetting.B_T_Ufp_CategoryService;

@SessionScope
public class CategoryAction extends BaseAction<B_T_Ufp_Category> {
	/**
	 * 版本控制信息
	 */
	private static final long serialVersionUID = 6179604301571294802L;
	private B_T_Ufp_Category b_T_Ufp_Category;
	@Autowired
	private B_T_Ufp_CategoryService b_T_Ufp_CategoryService;
	private String checkIds;
	private String flag;
	private String categoryStatus;
	//用于传递我的工程时 给具体部位增加数据时，传递uuid和那么给他的子类。
	private String positiontype;
	private List<B_T_Ufp_Category> list_b_T_Ufp_Category;
	//是否可以修改价格
		private String isupdate;
	/*******************STRUTS ACTION METHOD*************************/
	//删除
	public String categoryDelete() throws Exception {
		int i=b_T_Ufp_CategoryService.delete(checkIds);
		if(i>0)
//		return ajaxForwardSuccess(getText("msg.operation.success"), "accountList","", "forward", "systemsetting/Category_buweiList");
				if("0".equals(flag))
				{
					return ajaxForwardSuccess(getText("msg.operation.success"), "","accountDetail", "closeCurrent", "");
				}
				else if("1".equals(flag))
				{
					return ajaxForwardSuccess(getText("msg.operation.success"), "","accountDetailH", "closeCurrent", "");
				}
				else if(b_T_Ufp_Category.getCategoryStatus().equals("0"))
				{
					return ajaxForwardSuccess(getText("msg.operation.success"), "","accountDetail", "closeCurrent", "");
				}
				else
				{
					return ajaxForwardSuccess(getText("msg.operation.success"), "","accountDetailH", "", "");
				}
		else if(i==0)
		{
			return ajaxForwardError(getText("此类别下有数据无法删除"));
		}
				return ajaxForwardError(getText("msg.operation.failure"));
	}
	//修改新增
	public String categoryUpdate() throws Exception {
		if(b_T_Ufp_Category.getStatus()==null)
		{
			b_T_Ufp_Category.setStatus("0");
			b_T_Ufp_Category.setCategoryStatus(categoryStatus); 
		}
			
		int i=b_T_Ufp_CategoryService.update(b_T_Ufp_Category);
		if(i>0)
			//目前只有点击提交后关闭
			if(b_T_Ufp_Category.getCategoryStatus().equals("0"))
			{
				return ajaxForwardSuccess(getText("msg.operation.success"), "","accountDetail", "closeCurrent", "");
			}
			else
			{
				return ajaxForwardSuccess(getText("msg.operation.success"), "","accountDetailH", "closeCurrent", "");
			}
		//保存不关闭暂时没做
		//closeCurrent
		//return ajaxForwardSuccess(getText("msg.operation.success"), "categoryList","", "forward", "systemsetting/Category_categoryList");
		return ajaxForwardError(getText("msg.operation.failure"));
	}
	//类别名称查找带回
	public String projectCallback() throws Exception {
		b_T_Ufp_Category = new B_T_Ufp_Category();
		b_T_Ufp_Category.setCategoryStatus(categoryStatus);
		
		pager = new Pager<B_T_Ufp_Category>(pageNum, numPerPage,orderField,orderDirection);
		pager= b_T_Ufp_CategoryService.selectList(b_T_Ufp_Category,pager);
		return SUCCESS;
	}
	public String categoryList() throws Exception {
		b_T_Ufp_Category = new B_T_Ufp_Category();
		b_T_Ufp_Category.setCategoryStatus(categoryStatus);
		list_b_T_Ufp_Category=b_T_Ufp_CategoryService.select(b_T_Ufp_Category);
		return SUCCESS;
	}
	//我的工程中添加具体项目的时候用
	public String categoryRecycling() throws Exception {
		request.getSession().removeAttribute("item");
		if(positiontype!=null&&!"".equals(positiontype))
		{
			positiontype =Transcoding.getcode(request, positiontype);
//			positiontype =new String(positiontype.getBytes("ISO8859_1"),"GBK");
		}
		b_T_Ufp_Category = new B_T_Ufp_Category();
		b_T_Ufp_Category.setCategoryStatus(categoryStatus);
		//给pid设置0 的值，查询的时候不查pid为0的
		b_T_Ufp_Category.setPid("0");
		list_b_T_Ufp_Category=b_T_Ufp_CategoryService.select(b_T_Ufp_Category);
		return SUCCESS;
	}
	//局部刷新时使用
	public String buweiList() throws Exception {
		b_T_Ufp_Category = new B_T_Ufp_Category();
		b_T_Ufp_Category.setCategoryStatus(categoryStatus);
		
		list_b_T_Ufp_Category=b_T_Ufp_CategoryService.select(b_T_Ufp_Category);
//		pager = new Pager<B_T_Ufp_Category>(pageNum, numPerPage,orderField,orderDirection);
//		pager= b_T_Ufp_CategoryService.selectList(b_T_Ufp_Category,pager);
		return SUCCESS;
	}
	
	public String categoryDetail() throws Exception {
		if(b_T_Ufp_Category==null){
			b_T_Ufp_Category=b_T_Ufp_CategoryService.selectOne("");
			b_T_Ufp_Category=new B_T_Ufp_Category();
			b_T_Ufp_Category.setCategoryStatus(flag);
			
		}else{
			b_T_Ufp_Category=b_T_Ufp_CategoryService.selectOne(b_T_Ufp_Category.getUuid());
		}
		list_b_T_Ufp_Category = b_T_Ufp_CategoryService.selectchange(b_T_Ufp_Category);
		return SUCCESS;
	}
	
	
	/********************* class set/get ****************************/
	
	public B_T_Ufp_Category getB_T_Ufp_Category() {
		return b_T_Ufp_Category;
	}

	public void setB_T_Ufp_Category(B_T_Ufp_Category b_T_Ufp_Category) {
		this.b_T_Ufp_Category = b_T_Ufp_Category;
	}
	
	public String getCheckIds() {
		return checkIds;
	}

	public void setCheckIds(String checkIds) {
		this.checkIds = checkIds;
	}
	public String getFlag() {
		return flag;
	}
	public void setFlag(String flag) {
		this.flag = flag;
	}
	public String getCategoryStatus() {
		return categoryStatus;
	}
	public void setCategoryStatus(String categoryStatus) {
		this.categoryStatus = categoryStatus;
	}
	public List<B_T_Ufp_Category> getList_b_T_Ufp_Category() {
		return list_b_T_Ufp_Category;
	}
	public void setList_b_T_Ufp_Category(
			List<B_T_Ufp_Category> list_b_T_Ufp_Category) {
		this.list_b_T_Ufp_Category = list_b_T_Ufp_Category;
	}
	public String getPositiontype() {
		return positiontype;
	}
	public void setPositiontype(String positiontype) {
		this.positiontype = positiontype;
	}
	public String getIsupdate() {
		return isupdate;
	}
	public void setIsupdate(String isupdate) {
		this.isupdate = isupdate;
	}
}
